<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="../common/taglibs.jsp"%>
<sx:head/>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="StyleSheet" type="text/css" href="<%=request.getContextPath()%>/pages/css/common.css"></link>
<link rel="StyleSheet" type="text/css" href="<%=request.getContextPath()%>/pages/css/password.css"></link>
<script type="text/javascript" src="<%=request.getContextPath()%>/pages/js/password.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/pages/js/jquery-1.5.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/pages/js/jquery.validate.min.js" ></script>
<script type="text/javascript">

	function showSubCategories() {
	    dojo.event.topic.publish("showSubCategories");
	}
	
	function validate(sender){
		if(sender.value == ""){
			sender.value = 0;
		} 
	
	}
	
	$().ready(function(){
		$("#createProductForm").validate({
				rules: {
					name : {
						required: true,
						minlength: 2
					},
					code : {
						required: true,
						email: true
					}
				},
				messages: {
					name : {
						required: "Please enter sub category name",
						minlength: "Category name must consist of at least 2 characters"
					},
					code : {
						required: "Please enter sub category code",
						minlength: "Category code must consist of at least 4 characters"
					}
				}
		});
	});

	function chkStatus(s){
		var tr = $(s).parent().parent();
		$("#tblAvailableAirLines tr").each(function(){
			var act = $(this).index();
			if($(tr).index()==act){
				if(s.checked){
					$('input:text',$(this)).removeAttr('disabled','true');
					$('select',$(this)).removeAttr('disabled','true');
				}
				else{
					$('input:text',$(this)).attr('disabled','true');
					$('select',$(this)).attr('disabled','true');
				}
			}		
		});	
	}
</script>
<title>DFASS</title>
</head>
<body>
	<div class="headerContent" align="center">
		<div class="header">
		<%@ include file="../inc/logged_top.jsp" %>			
		</div>
		<div id="nav_container">
		<%@ include file="../menu/mb_menu_inventory.jsp" %>
	    </div>
	</div>
	<div class="bodyContent" align="center">
		<table><tr><td>&nbsp;</td></tr></table>
		<!-- This Empty Table is Required before the content of the body -->
		<s:form theme="simple" id="createProductForm" name="createProductForm" method="post" action="nextInProduct" enctype="multipart/form-data">		
			<table class="tblAdminNormal">
				<thead>
					<tr>
						
						<td colspan="4">Product Creation</td>
					</tr>
				</thead>
				<tbody>
				    <tr>
				        <td>Category</td>
				        <td> <s:select list="categories" name="cat" id="cat" 
				        									headerKey="0" headerValue="Select a category"  
				        									listKey="id"	listValue="name" 
				        									onchange="javascript:showSubCategories();return false;" />
						</td>
				    </tr>
				    <tr>
				    	<td> Sub Category </td>
				    	<td>
	                       	<s:url id="pri_url" action="showSubCategories" />
	                       	<sx:div id="deta" href="%{pri_url}" listenTopics="showSubCategories"
                                        formId="createProductForm" ></sx:div>
				    	</td>
				    </tr>
				    <tr>
				        <td>Code</td>
				        <td><s:textfield name="code" cssStyle="width:150px" /></td>
				    </tr>
				    <tr>
				        <td>Name</td>
				        <td><s:textfield name="name" cssStyle="width:150px" /></td>
				    </tr>
				    <tr>
				        <td>Description</td>
				        <td><s:textfield name="desc" cssStyle="width:150px" /></td>
				    </tr>
				    <tr>
				        <td>Vendor</td>
				        <td><s:textfield name="vendor" cssStyle="width:150px" /></td>
				    </tr>
				    <tr>
				        <td>Re-order level</td>
				        <td><s:textfield name="reOrderLevel" cssStyle="width:150px" /></td>
				    </tr>
				    <tr>
				        <td>Critical Lower Threshold</td>
				        <td><s:textfield name="clt" cssStyle="width:150px" /></td>
				    </tr>
				    <tr>
				    	<td colspan="5">
					    	<table id="tblAvailableAirLines">
					    		<tr><td></td></tr>
								<tr><th colspan="5"> Available Airlines </th></tr>
								<tr><td></td></tr>
								<tr>
									<th></th>
									<th>Airline Name</th>
									<th>Currency</th>
									<th>Unit Price</th>
									<th>Discount Rate</th>
								</tr>
								<s:iterator value="airlines" > 
								<tr>
									<td>
                       					<s:checkbox value="true" fieldValue="%{id}"  name="selectedAirlines" theme="simple" onchange="chkStatus(this)" />
									</td>
									<td><s:label value="%{name}"/></td>
									<td>
										<s:select list="currencies" name="airlineCurrencies" headerKey="0" 
														headerValue="Select a currency"	listKey="id" listValue="description" />									
									</td>
									<td><s:textfield name="airlineUnitPrices" value="0" onchange="validate(this)" /></td>
									<td><s:textfield name="airlineDiscountRates" value="0" onchange="validate(this)" /></td>
								</tr>
								</s:iterator>									    		
					    	</table>
				    	</td>
				    </tr>
				    <tr>
				        <td></td> 
				        <td><s:submit value="Next" cssClass="button" /></td> 
				    </tr>
				    <tr>
				        <td colspan="5"><s:actionmessage cssClass="successMsg" />
				        			<s:fielderror cssClass="errorMsg" /></td> 
				    </tr>
				</tbody>
			</table>		
		</s:form>
	</div>				
	
	<div class="footerContent" align="center">
		<div class="footer">
			<%@ include file="/pages/inc/footer.jsp" %>
		</div>
	</div>
</body>
</html>